#ifndef DCSFILEOPERATOR_H
#define DCSFILEOPERATOR_H

#include <QFile>

//最大分控数
#define SLAVE_MAX_NUM               128

//扇区大小
#define SECTOR_SIZE                 512

/*元数据扇区结构*/
typedef struct meta_sector
{
    unsigned int tag;                           /*固定标识*/
    unsigned char salt;                         /*加密因子*/
    unsigned int frame_num;                     /*视频文件总帧数*/
    unsigned char fps;                          /*帧率*/
    unsigned char remain_sector;                /*保留扇区数*/
    unsigned short map_sector;                  /*布线图数据扇区数*/
    unsigned short stream_start_sector_num;     /*视频数据起始扇区号*/

    unsigned char is_timer_trigger;             /*是否启用定时触发*/
    unsigned char is_play_immediately;          /*定时触发后是否立即播放*/
    unsigned char start_year;
    unsigned char start_month;
    unsigned char start_day;
    unsigned char start_hour;
    unsigned char start_minute;
    unsigned char start_second;
    unsigned char end_year;
    unsigned char end_month;
    unsigned char end_day;
    unsigned char end_hour;
    unsigned char end_minute;
    unsigned char end_second;
    unsigned char is_repeat;                            /*是否重复*/
    unsigned char week[7];

    unsigned char reserve1[282];

    unsigned char sync_type;                            /*同步方式选择*/
    unsigned short slave_start_id;                      /*分控ID起始编号*/
    unsigned short sector_per_frame;                    /*所有分控单帧视频数据占的扇区个数*/
    unsigned char slave_num;                            /*分控总数目N（最大支持128）*/
    unsigned char sector_per_slave_frame[SLAVE_MAX_NUM];  /*各分控单帧视频数据占的扇区数*/

    unsigned char reserve2[59];
}__attribute__((packed)) meta_sector_st;

class DCSFileOperator
{
public:
    DCSFileOperator(const QString &fileName);

    ~DCSFileOperator();

    struct meta_sector *meta() const;

    bool fileOpen();

    void fileClose();

    bool readMetaData();

    qint64 readOneFrameByNum(QByteArray &data, unsigned int frameNum);

private:
    QFile *mFileOp;
    struct meta_sector *mMeta;
};

#endif // DCSFILEOPERATOR_H
